﻿Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Drawing.Text

''' <summary>
''' 绘制圆管理类，用于绘制多个圆
''' </summary>
''' <remarks></remarks>
Public Class Circles
    Inherits WindBase
    Private m_R As Double = 0
    Private m_ArrayCircles(-1) As Circle
    ''' <summary>
    ''' 多个风玫瑰数组对象
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArrayCircles() As Circle()
        Get
            Return m_ArrayCircles
        End Get
        Set(ByVal value As Circle())
            m_ArrayCircles = value
        End Set
    End Property

    Private m_ArryDegreeSpeed()() As Double '按度绘图的数据数组--风速
    Private m_ArryAzimuthSpeed()() As Double '按方位绘图的数据数组--风速
    Private m_ArryDegreeFrequency()() As Double '按度绘图的数据数组--风频
    Private m_ArryAzimuthFrequency()() As Double '按方位绘图的数据数组--风频

    Private m_ArryWindRose() As Double '用于存储1个风玫瑰的数据
    Private m_ArryWindRoses()() As Double '用于存储n个风玫瑰的数据
    Private m_RoseLengCheck As New Rose.SetRoseLegend '用户选项

    ''' <summary>
    ''' 按度绘图的数据数组--风速
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArryDegreeSpeed() As Double()()
        Get
            Return m_ArryDegreeSpeed
        End Get
        Set(ByVal value As Double()())
            m_ArryDegreeSpeed = value
        End Set
    End Property
    ''' <summary>
    '''按方位绘图的数据数组--风速
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArryAzimuthSpeed() As Double()()
        Get
            Return m_ArryAzimuthSpeed
        End Get
        Set(ByVal value As Double()())
            m_ArryAzimuthSpeed = value
        End Set
    End Property
    ''' <summary>
    ''' 按度绘图的数据数组--风频
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArryDegreeFrequency() As Double()()
        Get
            Return m_ArryDegreeFrequency
        End Get
        Set(ByVal value As Double()())
            m_ArryDegreeFrequency = value
        End Set
    End Property
    ''' <summary>
    ''' 按方位绘图的数据数组--风频
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArryAzimuthFrequency() As Double()()
        Get
            Return m_ArryAzimuthFrequency
        End Get
        Set(ByVal value As Double()())
            m_ArryAzimuthFrequency = value
        End Set
    End Property
    ''' <summary>
    ''' 用户选项
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property RoseLengCheck() As Rose.SetRoseLegend
        Get
            Return m_RoseLengCheck
        End Get
        Set(ByVal value As Rose.SetRoseLegend)
            m_RoseLengCheck = value
        End Set
    End Property

    ''' <summary>
    ''' 画玫瑰图的图案填充
    ''' </summary>
    ''' <param name="grap"></param>
    ''' <param name="BackColor"></param>
    ''' <remarks></remarks>
    Public Sub Draw(ByVal grap As Graphics, ByVal BackColor As Color)
        If m_RoseLengCheck.ModeCheck = True And m_RoseLengCheck.SpeedFrequencyCheck = True Then
            m_ArryWindRoses = ArryDegreeSpeed
        ElseIf m_RoseLengCheck.ModeCheck = True And m_RoseLengCheck.SpeedFrequencyCheck = False Then
            m_ArryWindRoses = ArryDegreeFrequency
        ElseIf m_RoseLengCheck.ModeCheck = False And m_RoseLengCheck.SpeedFrequencyCheck = True Then
            m_ArryWindRoses = ArryAzimuthSpeed
        ElseIf m_RoseLengCheck.ModeCheck = False And m_RoseLengCheck.SpeedFrequencyCheck = False Then
            m_ArryWindRoses = ArryAzimuthFrequency
        End If
        If m_RoseLengCheck.ModeCheck = True Then
            ReDim m_ArryWindRose(36)
            m_ArryWindRose(36) = 0
        Else
            ReDim m_ArryWindRose(16)
            m_ArryWindRose(16) = 0
        End If

        Dim mCols As Integer = 1 '判断是否该在下一行显示累加器
        Dim mRows As Integer = 1 '行数
        Dim Location As PointF
        Dim indexCount As Integer = 0

        'Dim mCheckParity As Boolean = False '判断用3行显示还是用2行
        Dim mCount As Integer = 0
        For i As Integer = 0 To RoseLengCheck.ArryShowData.Length - 1
            If RoseLengCheck.ArryShowData(i) > 1 Then
                mCount = mCount + 1
                'If mCount Mod 3 = 0 Then
                '    mCheckParity = True
                'Else
                '    mCheckParity = False
                'End If
            End If
        Next

        For k As Integer = 0 To RoseLengCheck.ArryShowData.Length - 1
            '全部数据
            If RoseLengCheck.ArryShowData(k) = 1 Then
                ComPareValues()
                For i As Integer = 0 To m_ArrayCircles.Length - 1
                    Location.X = (mCols - 1) * m_R * 2 * 1.4
                    For j As Integer = 0 To m_ArryWindRose.Length - 1
                        If RoseLengCheck.SpeedFrequencyCheck Then
                            m_ArryWindRose(j) = m_ArryWindRoses(i)(j)
                        Else
                            m_ArryWindRose(j) = m_ArryWindRoses(i)(j) '绘制风速玫瑰图
                        End If
                        '风速/风频数据
                        m_ArrayCircles(i).CheckDreFre = m_RoseLengCheck.SpeedFrequencyCheck
                    Next
                    m_ArrayCircles(i).Location = Location

                    '标注名称
                    Dim ArrySumDre() As String = {"一月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "二月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "三月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "四月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "五月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "六月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "七月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "八月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "九月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "十月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "十一月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "十二月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "全年，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "春季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "夏季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "秋季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "冬季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s"}
                    Dim ArrySumFre() As String = {"一月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "二月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "三月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "四月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "五月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "六月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "七月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "八月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "九月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "十月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "十一月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "十二月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "全年，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "春季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "夏季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "秋季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "冬季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%"}
                    Dim ArrySum() As String
                    If RoseLengCheck.SpeedFrequencyCheck Then
                        ReDim ArrySum(ArrySumDre.Length - 1)
                        ArrySum = ArrySumDre
                    Else
                        ReDim ArrySum(ArrySumFre.Length - 1)
                        ArrySum = ArrySumFre '绘制风速玫瑰图
                    End If
                    Dim mMoonth As Integer = 0
                    Dim Arry As String = ""
                    For Each Arry In ArrySum
                        If mMoonth = i Then
                            Exit For
                        End If
                        mMoonth = mMoonth + 1
                    Next
                    m_ArrayCircles(i).Draw(grap, BackColor, m_ArryWindRose, m_RoseLengCheck.ModeCheck, Arry)
                    '每2个玫瑰图一行
                    If mCols Mod 4 = 0 Then
                        Location.Y = -mRows * m_R * 2 * 1.4
                        mRows = mRows + 1
                        mCols = 0
                    End If
                    mCols = mCols + 1
                Next
                Exit For
            End If

            If RoseLengCheck.ArryShowData(k) > 1 Then
                ComPareValues()
                Location.X = (mCols - 1) * m_R * 2 * 1.4
                For j As Integer = 0 To m_ArryWindRose.Length - 1
                    If m_RoseLengCheck.SpeedFrequencyCheck Then
                        m_ArryWindRose(j) = m_ArryWindRoses(RoseLengCheck.ArryShowData(k) - 2)(j) '按方位绘制风速玫瑰图
                    Else
                        m_ArryWindRose(j) = m_ArryWindRoses(RoseLengCheck.ArryShowData(k) - 2)(j)
                    End If
                Next
                '风速/风频数据
                m_ArrayCircles(k).CheckDreFre = m_RoseLengCheck.SpeedFrequencyCheck
                m_ArrayCircles(indexCount).Location = Location

                '标注名称
                Dim ArrySumDre() As String = {"一月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "二月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "三月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "四月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "五月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "六月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "七月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "八月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "九月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "十月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "十一月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "十二月，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "全年，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "春季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "夏季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "秋季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s", "冬季，平均" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "m/s"}
                Dim ArrySumFre() As String = {"一月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "二月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "三月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "四月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "五月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "六月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "七月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "八月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "九月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "十月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "十一月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "十二月，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "全年，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "春季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "夏季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "秋季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%", "冬季，静风" & m_ArryWindRose(m_ArryWindRose.Length - 1) & "%"}
                Dim ArrySum() As String
                If RoseLengCheck.SpeedFrequencyCheck Then
                    ReDim ArrySum(ArrySumDre.Length - 1)
                    ArrySum = ArrySumDre
                Else
                    ReDim ArrySum(ArrySumFre.Length - 1)
                    ArrySum = ArrySumFre '绘制风速玫瑰图
                End If
                Dim mMoonth As Integer = 0
                Dim Arry As String = ""
                For Each Arry In ArrySum '传输数据“月份“
                    If mMoonth = RoseLengCheck.ArryShowData(k) - 2 Then
                        Exit For
                    End If
                    mMoonth = mMoonth + 1
                Next
                m_ArrayCircles(indexCount).Draw(grap, BackColor, m_ArryWindRose, m_RoseLengCheck.ModeCheck, Arry)
                '是用3行/2行来显示玫瑰图
                'Dim mMod As Integer = 0
                'If mCheckParity Then
                '    mMod = 3
                'Else
                '    mMod = 4
                'End If
                '每2个玫瑰图一行
                If mCount < 6 Then
                    If mCols Mod 2 = 0 Then
                        Location.Y = -mRows * m_R * 2 * 1.4
                        mRows = mRows + 1
                        mCols = 0
                    End If
                ElseIf mCount >= 6 And mCount <= 12 Then
                    If mCols Mod 3 = 0 Then
                        Location.Y = -mRows * m_R * 2 * 1.4
                        mRows = mRows + 1
                        mCols = 0
                    End If
                ElseIf mCount > 12 Then
                    If mCols Mod 4 = 0 Then
                        Location.Y = -mRows * m_R * 2 * 1.4
                        mRows = mRows + 1
                        mCols = 0
                    End If
                End If
                mCols = mCols + 1
                indexCount = indexCount + 1
            End If
        Next
    End Sub

    ''' <summary>
    ''' 数值的比较找出一个最大的值，以确定绘图的半径
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ComPareValues()
        Dim mMaxValue As Double = 0
        Dim mCompareValue As Double = 0
        For i As Integer = 0 To m_ArrayCircles.Length - 1
            For j As Integer = 0 To m_ArryWindRose.Length - 1
                If RoseLengCheck.SpeedFrequencyCheck Then
                    m_ArryWindRose(j) = m_ArryWindRoses(i)(j) '绘制风速玫瑰图
                Else
                    m_ArryWindRose(j) = m_ArryWindRoses(i)(j)
                End If
            Next
            Array.Sort(m_ArryWindRose, 0, m_ArryWindRose.Length - 1)
            Array.Reverse(m_ArryWindRose, 0, m_ArryWindRose.Length - 1)
            mCompareValue = m_ArryWindRose(0)
            If mMaxValue < mCompareValue Then
                mMaxValue = mCompareValue
            End If
        Next
        '决定每个玫瑰图的半径
        Dim n As Integer = 5
        For i As Integer = 0 To m_ArrayCircles.Length - 1
            m_ArrayCircles(i).Count = n
            m_ArrayCircles(i).Interval = FormatNumber(mMaxValue / n, 1)
        Next
        m_R = FormatNumber(mMaxValue / n, 1) * n

    End Sub
End Class
